/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!		\file		cc_l2dn.h
  \date		june 2010
  \author		TNick

  \brief		Contains the definition of CC_L2DN class and related


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 These lists are simple chains of objects. Each list must have
 - a header (CC_HDL2DN) that holds a pointer to the first item
 - a number of 0 or more items that inherit from CC_L2DN (holding only a
 forward and a backward pointer and a name)

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef		__CC_L2DN_INC__
#define		__CC_L2DN_INC__
#ifdef		__cplusplus
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

class	CC_L2DN;

#include	<assert.h>

#include	<QString>

#include	"cc_l2d.h"

/*  INCLUDES    ============================================================ */
//
//
//
//


/* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
/// list header
class	CC_HDL2DN : public CC_HDL2D {
	//
	//
	//
	//
	/*  DEFINITIONS    --------------------------------------------------------- */
	friend	class	CC_L2DN;

	/*  DEFINITIONS    ========================================================= */
	//
	//
	//
	//
	/*  DATA    ---------------------------------------------------------------- */



	/*  DATA    ================================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ----------------------------------------------------------- */

public:
	/// constructor;
	CC_HDL2DN() : CC_HDL2D() {}

	/// destructor; will free resources;
	virtual				~CC_HDL2DN(){}

	/// get the index of an element based on name
	inline int			indexFromName	(
		QString		strToCheck,			/**< the string in question */
		bool		bCaseSens = false	/**< is the check case sensitive or not*/
		);

	/// get the pointer to an element based on name
	inline CC_L2DN*		itemFromName		(
		QString		strToCheck,			/**< the string in question */
		bool		bCaseSens = false	/**< is the check case sensitive or not*/
		);

	/// tell if a string is present inside
	inline bool			hasName				(
		QString		strToCheck,			/**< the string in question */
		bool		bCaseSens = false	/**< is the check case sensitive or not*/
		)
	{
		return (indexFromName(strToCheck,bCaseSens) != -1);
	}

	/// get a pointer based on name


	/*  FUNCTIONS    =========================================================== */
	//
	//
	//
	//
};	/*	class	CC_HDL2DN	*/
//
//
//
//
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
/* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */



/* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
/// list element
class	CC_L2DN : public CC_L2D {
	//
	//
	//
	//
	/*  DEFINITIONS    --------------------------------------------------------- */
	friend	class	CC_HDL2DN;

	/*  DEFINITIONS    ========================================================= */
	//
	//
	//
	//
	/*  DATA    ---------------------------------------------------------------- */

	/// the name of the item
protected:	QString		str_name;

	/*  DATA    ================================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ----------------------------------------------------------- */


	/// constructor; creates a simple, unnamed, hanging element
public: inline				CC_L2DN() : CC_L2D() {}

	/// constructor; appends this item to the chain managed by pFth
public: inline				CC_L2DN(CC_HDL2DN* pFth) : CC_L2D(pFth) {}

	/// constructor; creates a simple, named, hanging element
public: inline				CC_L2DN(QString nm) : CC_L2D()
	{str_name = nm; }

	/// constructor; appends this item to the chain managed by pFth
public: inline				CC_L2DN(QString nm, CC_HDL2DN* pFth) : CC_L2D(pFth)
	{str_name = nm; }

	/// destructor; will free resources;
public: virtual				~CC_L2DN(){}



	/// get the name of this element
public: inline QString		Name	(void)
	{ return str_name; }
	/// set the name of this element
public: inline void			setName	(QString sNewName)
	{ str_name = sNewName; }




	/*  FUNCTIONS    =========================================================== */
	//
	//
	//
	//
};	/*	class	CC_L2DN	*/
//
//
//
//
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
/* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */


/* ------------------------------------------------------------------------- */
inline int			CC_HDL2DN::indexFromName	(QString strToCheck, bool bCaseSens)
{
	CC_L2DN*	pRet = static_cast<CC_L2DN*>(Lip1);

	Qt::CaseSensitivity cs;
	if (bCaseSens)
		cs = Qt::CaseSensitive;
	else
		cs = Qt::CaseInsensitive;
	int		i = 0;
	while (pRet != NULL)
		{
            if (0 == pRet->Name().compare(strToCheck, cs))
				return i;
			pRet = static_cast<CC_L2DN*>(pRet->next());
			i++;
		}
	return -1;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
inline CC_L2DN*		CC_HDL2DN::itemFromName		(QString strToCheck, bool bCaseSens)
{
	CC_L2DN*	pRet = static_cast<CC_L2DN*>(Lip1);

	Qt::CaseSensitivity cs;
	if (bCaseSens)
		cs = Qt::CaseSensitive;
	else
		cs = Qt::CaseInsensitive;
	while (pRet != NULL)
		{
			if (0 == pRet->Name().compare(strToCheck, cs))
				return pRet;
			pRet = static_cast<CC_L2DN*>(pRet->next());
		}
	return NULL;
}
/* ========================================================================= */




#endif	//	__cplusplus
#endif	//	__CC_L2DN_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */


